apiVersion: apps/v1
kind: Deployment
metadata:
  name: dice-roller
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    matchLabels:
      app: dice-roller
  replicas: 10
  template:
    metadata:
      labels:
        app: dice-roller
        'backstage.io/kubernetes-id': dice-roller
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          args:
            - bash
            - -c
            - yes > /dev/null & yes > /dev/null & yes > /dev/null
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '50m'
          ports:
            - containerPort: 80

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dice-roller-incorrect-probe
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    matchLabels:
      app: dice-roller-incorrect-probe
  replicas: 2
  template:
    metadata:
      labels:
        app: dice-roller-incorrect-probe
        'backstage.io/kubernetes-id': dice-roller
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '50m'
          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
          ports:
            - containerPort: 80

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dice-roller-canary
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    matchLabels:
      app: dice-roller-canary
  replicas: 2
  template:
    metadata:
      labels:
        app: dice-roller-canary
        'backstage.io/kubernetes-id': dice-roller
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
            - containerPort: 80
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '500m'
        - name: side-car
          image: nginx:1.14.2
          ports:
            - containerPort: 81
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '500m'
        - name: other-side-car
          image: nginx:1.14.2
          ports:
            - containerPort: 82
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '500m'

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dice-roller-bad-config
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    matchLabels:
      app: dice-roller-bad-config
  replicas: 2
  template:
    metadata:
      labels:
        app: dice-roller-bad-config
        'backstage.io/kubernetes-id': dice-roller
    spec:
      containers:
        - name: nginx
          image: nginx:6000000
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '500m'
          ports:
            - containerPort: 80

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dice-roller-big
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    matchLabels:
      app: dice-roller-big
  replicas: 1
  template:
    metadata:
      labels:
        app: dice-roller-big
        'backstage.io/kubernetes-id': dice-roller
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          resources:
            requests:
              memory: '64Mi'
              cpu: '100000m'
            limits:
              memory: '128Mi'
              cpu: '100000m'
          ports:
            - containerPort: 80

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dice-roller-bad-cm
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    matchLabels:
      app: dice-roller-bad-cm
  replicas: 1
  template:
    metadata:
      labels:
        app: dice-roller-bad-cm
        'backstage.io/kubernetes-id': dice-roller
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          env:
            - name: SOME_ENV_VAR
              valueFrom:
                configMapKeyRef:
                  name: some-cm
                  key: some-key
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
            limits:
              memory: '128Mi'
              cpu: '500m'
          ports:
            - containerPort: 80

---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: dice-roller
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: dice-roller
  minReplicas: 10
  maxReplicas: 15
  targetCPUUtilizationPercentage: 50

---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: dice-roller-cronjob
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  schedule: '*/1 * * * *'
  jobTemplate:
    metadata:
      labels:
        'backstage.io/kubernetes-id': dice-roller
    spec:
      template:
        metadata:
          labels:
            'backstage.io/kubernetes-id': dice-roller
        spec:
          containers:
            - name: busybox
              image: busybox
              imagePullPolicy: IfNotPresent
              command:
                - /bin/sh
                - -c
                - date; echo Rolling a die!
          restartPolicy: OnFailure

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dice-roller
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  rules:
    - host: nginx
      http:
        paths:
          - path: /
            backend:
              serviceName: dice-roller
              servicePort: 80

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: dice-roller
  namespace: default
  labels:
    'backstage.io/kubernetes-id': dice-roller
data:
  foo: bar

---
apiVersion: v1
kind: Secret
metadata:
  name: dice-roller
  labels:
    'backstage.io/kubernetes-id': dice-roller
type: Opaque
data:
  username: YWRtaW4=
---
apiVersion: v1
kind: Service
metadata:
  name: dice-roller
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    app: dice-roller
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
      name: port1
    - protocol: TCP
      port: 81
      targetPort: 9377
      name: port2

---
apiVersion: v1
kind: Service
metadata:
  name: dice-roller-lb
  labels:
    'backstage.io/kubernetes-id': dice-roller
spec:
  selector:
    app: dice-roller
  ports:
    - port: 8765
      targetPort: 9376
  type: LoadBalancer

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: dice-roller
automountServiceAccountToken: false

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: sa-admin
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
subjects:
  - kind: ServiceAccount
    name: dice-roller
    namespace: default
